<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2018/10/16
 * Time: 11:43
 */
header("Content-Type:text/html;charset=utf-8");
include 'includes/init.php';

$action = isset($_REQUEST['action'])?$_REQUEST['action']:'';
$back = null;

if ($action == 'search'){
    $value = isset($_REQUEST['value'])?$_REQUEST['value']:'';
    $search_sql = "select id,names,email,phone,company_data,rule_id from t_member where names like '%$value%' or phone like '%$value%'";
    $search_data = $db_Obj->getall($search_sql);
    if ($search_data){
        $back = array('code' => 200,'data' => $search_data);
    } else {
        $back = array('code' => 100);
    }
}

if ($action == 'change'){
    $id = isset($_REQUEST['id'])?$_REQUEST['id']:'';
    $rule_id = isset($_REQUEST['rule_id'])?$_REQUEST['rule_id']:"";
    $rate = isset($_REQUEST['rate'])?$_REQUEST['rate']:"";
    $change_sql = "update t_member set rule_id = '$rule_id',rate='$rate' where id = $id";
    if ($db_Obj->query($change_sql)){
        $back = array('code' => 200);
    } else {
        $back = array('code' => 100);
    }
}

echo json_encode($back);